﻿using Zpb;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
using UtilLib;
using gpb = global::Google.Protobuf;

namespace client
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            App.WdMain = this;

        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            ColumnGridNav.Width = new GridLength(0);
            GridNav.Visibility = Visibility.Hidden;

            PageOn("PageDebug");
            PageOn("PageLogin");

            //TextBoxserverID.Text = "0";
            //TextBoxtrid.Text = "TR10224";
            //TextBoxtrid.Text = "TR10230";
            //TextBoxtrid.Text = "TR10273";
        }
        #region 页面切换
        private void ButtonPage_Checked(object sender, RoutedEventArgs e)
        {
            var button = (RadioButton)sender;
            var pageName = button.Tag.ToString();
            PageOn(pageName);
        }
        public static Dictionary<string, Page> DictPage = new Dictionary<string, Page>();
        public void PageOn(string pageName)
        {
            //if (pageName == "PageLogin")
            //{
            //    PageSetWidth(600);
            //}
            //else
            //{
            //    PageSetWidth(1200);
            //}
            if (DictPage.TryGetValue(pageName, out var page))
            {
                FrameMain.Content = page;
                return;
            }
            string uri = "client." + pageName;
            Type type = Type.GetType(uri);
            if (type != null)
            {
                object obj = type.Assembly.CreateInstance(uri);
                page = obj as Page;
                FrameMain.Content = page;
                DictPage[pageName] = page;
            }
        }
        private void PageSetWidth(double ww)
        {
            if (Width != ww)
            {
                Width = ww;
            }
        }
        #endregion
        
        //private void Button_Click_Public(object sender, RoutedEventArgs e)
        //{
        //    var btn = sender as Button;
        //    var Content = btn.Content.ToString();
        //    switch (Content)
        //    {
        //        case "连接到服务器":
        //            if (App.socket.SocketStart())
        //            {
        //                ButtonLogin.IsEnabled = true;
        //            }
        //            break;
        //        case "玩家登录":
        //            {
        //                PlayerLoginReq req = new();
        //                req.ServerID = TextBoxserverID.Text.ToInt();
        //                req.Trid = TextBoxtrid.Text;
        //                Send(EPid.PplayerLoginReq, req);
        //                ButtonChat.IsEnabled = true;
        //            }
        //            break;
        //        case "聊天发送":
        //            {
        //                //ChatMessageSendReq req = new();
        //                //req.ChatType = ComboBoxChatType.SelectedValue.ToString() switch
        //                //{
        //                //    "世界" => EChatType.ChatTypeWorld,
        //                //    "公会" => EChatType.ChatTypeGuild,
        //                //    "私聊" => EChatType.ChatTypePersonal,
        //                //    "跨游戏" => EChatType.ChatTypeUniverse,
        //                //    _ => EChatType.ChatTypeWorld,
        //                //};
        //                //req.Text = TextBoxChatMessage.Text;
        //                //Send(EPid.PchatMessageSendReq, req);
        //            }
        //            break;
        //        default:
        //            break;
        //    }
        //}
    }
}
